package com.app.mingluxing.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.app.mingluxing.R;
import com.app.mingluxing.bean.MyResult;
import com.app.mingluxing.widget.CircleImageView;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.display.SimpleBitmapDisplayer;

import java.util.List;

/**
 *
 * Created by Aaron on 15/8/11.
 */
public class MyBabyAdapter extends BaseAdapter {

    private List<MyResult.MyData> tempList;
    private Context ctx;
    public DisplayImageOptions options;
    public MyBabyAdapter(Context ctx ,List<MyResult.MyData> tempList) {
        this.ctx = ctx;
        this.tempList = tempList;

        options = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.drawable.icon_person)
                .showImageForEmptyUri(R.drawable.icon_person)
                .showImageOnFail(R.drawable.icon_person)
                .resetViewBeforeLoading(true)
                .cacheOnDisk(true).cacheInMemory(true)
                .cacheOnDisc(true).imageScaleType(ImageScaleType.EXACTLY)
                .bitmapConfig(Bitmap.Config.RGB_565)
                .considerExifParams(true)
                .displayer(new SimpleBitmapDisplayer()).build();

    }

    public void setData(List<MyResult.MyData> tempList){
        this.tempList = tempList;
    }

    @Override
    public int getCount() {
        return tempList.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder = null;

        if (convertView == null) {

            convertView = View.inflate(ctx, R.layout.item_my_baby, null);
            viewHolder = new ViewHolder();
            viewHolder.iv_head_pic = (CircleImageView) convertView.findViewById(R.id.iv_head_pic);
            viewHolder.tv_my_name = (TextView) convertView.findViewById(R.id.tv_my_name);
            viewHolder.tv_watch_tel = (TextView) convertView.findViewById(R.id.tv_watch_tel);
            viewHolder.tv_attention_people = (TextView) convertView.findViewById(R.id.tv_attention_people);
            convertView.setTag(viewHolder);

        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        ImageLoader.getInstance().displayImage(tempList.get(position).picUrl,viewHolder.iv_head_pic,options);
        viewHolder.tv_my_name.setText(tempList.get(position).nickName);
        viewHolder.tv_attention_people.setText(tempList.get(position).classInfo);
        viewHolder.tv_watch_tel.setText(tempList.get(position).phoneNum);
        return convertView;
    }

    private class ViewHolder {

        private TextView tv_my_name;
        private TextView tv_watch_tel;
        private TextView tv_attention_people;
        private CircleImageView iv_head_pic;

    }
}
